﻿using Face8280WebSocketServer.DB;
using Face8280WebSocketServer.DB.Device;
using Face8280WebSocketServer.DB.People;
using Face8280WebSocketServer.DTO.FaceDevice;
using Face8280WebSocketServer.DTO.FacePeople;
using Face8280WebSocketServer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Face8280WebSocketServer.Interface
{
    /// <summary>
    /// 缓存预热服务
    /// </summary>
    public interface ICacheService : IBaseService
    {
        bool LoadCache();

        /// <summary>
        /// 根据SN获取设备信息
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        FaceDeviceStatus GetDevice(string sn);

        /// <summary>
        /// 根据SN获取设备信息
        /// </summary>
        /// <returns></returns>
        List<FaceDeviceStatus> GetDevices();

        /// <summary>
        /// 获取设备实时在线状态
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        List<FaceDeviceDetail_PageModel> GetDeviceOnlineStatus(List<FaceDeviceDetail_PageModel> sn);

        /// <summary>
        /// 添加设备缓存--新增设备时使用
        /// </summary>
        /// <param name="oDevice"></param>
        /// <returns></returns>
        bool AddDeviceCache(FaceDeviceInfo oDevice);



        /// <summary>
        /// 更新设备缓存
        /// </summary>
        /// <param name="oDevice"></param>
        /// <param name="oAccessTotal"></param>
        /// <returns></returns>
        bool UpdateDeviceCache(FaceDeviceInfo oDevice, (int NewPeople, int DelPeople, int RemoteCount, int AccessTotal) oAccessTotal);

        /// <summary>
        /// 更新设备缓存，指示需要换成的内容
        /// </summary>
        /// <param name="oDevice"></param>
        /// <returns></returns>
        bool UpdateDeviceCache(FaceDeviceInfo oDevice, Action<Dictionary<string, string>, FaceDeviceInfo> updateAction);

        /// <summary>
        /// 替换设备SN
        /// </summary>
        /// <param name="sOldSN"></param>
        /// <param name="sNewSN"></param>
        /// <returns></returns>
        bool ReplaceDeviceSN(string sOldSN, string sNewSN);

        /// <summary>
        /// 删除设备缓存
        /// </summary>
        /// <param name="oDevices"></param>
        /// <returns></returns>
        bool DeleteDeviceCache(string sn);


        /// <summary>
        /// 更新设备远程操作缓存
        /// </summary>
        /// <param name="oDevices"></param>
        /// <returns></returns>
        void UpdateDeviceRemoteCache(Dictionary<string, int> oTotals);


        /// <summary>
        /// 更新设备权限缓存
        /// </summary>
        /// <param name="oDevices"></param>
        /// <returns></returns>
        public void UpdateDeviceAccessCache(Dictionary<string, (int NewPeople, int DelPeople, int AccessTotal)> oTotals);

        /// <summary>
        /// 更新设备权限缓存
        /// </summary>
        /// <param name="oDevices"></param>
        /// <returns></returns>
        public void UpdateDeviceAccessCache(string sn ,Action<Dictionary<string, string>> callblack);


        /// <summary>
        /// 获取设备任务详情
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        (int NewPeople, int DelPeople, int AccessTotal, int RemoteCount, int EmptyPeople) GetTaskDetail(string sn);


        /// <summary>
        /// 获取指定设备的SN查询需要同步的人员数和设备ID
        /// </summary>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        int GetNewPeopleTotal(string deviceSN);

        /// <summary>
        /// 保存设备拉取的人员编号列表
        /// </summary>
        /// <param name="sSN"></param>
        /// <param name="enumerable"></param>
        void SaveDeviceReadPeopleCodeList(string sSN, IEnumerable<long> PeopleCodes);

        /// <summary>
        /// 获取设备拉取的人员编号列表
        /// </summary>
        /// <param name="sSN"></param>
        /// <returns></returns>
        (List<long> Codes, int DoorID) GetDeviceReadPeopleCodeList(string sSN);

        /// <summary>
        /// 从缓存中删除设备拉取的人员编号列表
        /// </summary>
        /// <param name="sSN"></param>
        void DeleteDeviceReadPeopleCodeList(string sSN);

        /// <summary>
        /// 保存设备拉取的待删除人员编号列表
        /// </summary>
        /// <param name="sSN"></param>
        /// <param name="PeopleCodes"></param>
        void SaveDeviceDeletePeopleCodeList(string sSN, IEnumerable<long> PeopleCodes);

        /// <summary>
        /// 获取设备拉取的待删除人员编号列表
        /// </summary>
        /// <param name="sSN"></param>
        /// <returns></returns>
        (List<long> Codes, int DoorID) GetDeviceDeletePeopleCodeList(string sSN);

        /// <summary>
        /// 从缓存中删除设备拉取的待删除人员编号列表
        /// </summary>
        /// <param name="sSN"></param>
        void DeleteDeviceDeletePeopleCodeList(string SN);


        /// <summary>
        /// 根据SN获取缓存的设备详情
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        FaceDeviceInfo GetDeviceDetail(string sn);

        /// <summary>
        /// 更新设备清空人员标志位
        /// </summary>
        /// <param name="dic"></param>
        void UpdateDeviceEmptyPeopleCache(Dictionary<string, int> dic);
        /// <summary>
        /// 从设备缓存获取Hash字典中的指定键值
        /// </summary>
        /// <param name="sn"></param>
        /// <param name="key"></param>
        /// <param name="dic"></param>
        /// <returns></returns>
        bool GetDeviceCacheHashValue(string sn, HashSet<string> key, Dictionary<string, string> dic);
       // public void AddPeopleImageBase64(uint id, byte[] data);
      //  public string GetPeopleImageBase64(uint id);

        public void UpdateDeviceAccessTotal1(Dictionary<int, FacePeopleInfo> peopleList, List<FaceDeviceStatus> list, List<FacePeopleAccessDetail> accessList);
        public PeopleImageInfo GetPeopleImage(uint id);
    }
}
